package com.BahavioralPartterns.ChainOfResponsibility;

import java.util.Random;

import com.BahavioralPartterns.ChainOfResponsibility.handle.IHandler;
import com.BahavioralPartterns.ChainOfResponsibility.impl.SchoolMasterHandler;
import com.BahavioralPartterns.ChainOfResponsibility.impl.SquadLeaderHandler;
import com.BahavioralPartterns.ChainOfResponsibility.impl.TeacherHandler;
import com.BahavioralPartterns.ChainOfResponsibility.message.IStudent;
import com.BahavioralPartterns.ChainOfResponsibility.message.Student;

public class CommonClient {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 班长处理者
		IHandler sqmshandler = new SquadLeaderHandler();
		// 老师处理者
		IHandler techhandler = new TeacherHandler();
		// 校长处理者
		IHandler scmshandler = new SchoolMasterHandler();
		// 创建随机数对象 用来随机产生学生对象
		Random random = new Random();
		for (int i = 0; i < 3; i++) {
			// 获得随机数
			int radom = random.nextInt(3);
			IStudent student = new Student(radom, "学生" + i + "生病了，要请假！");
			System.out.println("#################################");
			// 处理消息
			if (0 == student.getState()) {
				// 如果请假级别和当前一致 则当前对象进行处理
				sqmshandler.handleRequest(student);
			} else {
				System.out.println("请求上级领导批复！");
				if (1 == student.getState()){
					techhandler.handleRequest(student);
				}else{
					System.out.println("请求上级领导批复！");
					scmshandler.handleRequest(student);
				}
			}
			System.out.println("#################################\n");
		}

	}
}
